data_table = [
    [1, 2, 3, 4],  # rank
    ["red", "purple", "blue", "green"],  # bycle
    ["Mike", "Ellie", "Rohan", "Fatma"],  # do not need to move (names)
]
# data table 的逻辑需要优化

level_length = 4
table_length = 2


# 还是一个函数一个循环,一个函数多个循环会很乱呢


def check_constrain():
    """check_constrain"""
    # name constrain
    # (rank/bycle),name
    # 可优化
    if (
        data_table[0][0] == 1
        or data_table[0][0] == 4
        or data_table[0][1] == 1
        or data_table[0][1] == 4
    ):  # Mike 和 Ellie 不是第一,也不是最后
        return

    # Ellie 骑紫色的车,Rohan没有骑绿色的车
    if data_table[1][1] != "purple" or data_table[1][2] == "green":
        return

    # 骑蓝色车的人领先Fatma
    # 骑绿色车的人领先骑紫色车的人
    fatma_rank = data_table[0][3]
    # blue_rank
    # green_rank
    # purple_rank
    for i in range(level_length):

        if data_table[1][i] == "blue":
            blue_rank = data_table[0][i]

        if data_table[1][i] == "green":
            green_rank = data_table[0][i]

        if data_table[1][i] == "purple":
            purple_rank = data_table[0][i]

        if data_table[0][i] == 2:
            rank2 = data_table[2][i]

    if blue_rank < fatma_rank:
        if green_rank < purple_rank:
            print(data_table)
            print(rank2)
    return


def bycle_arrange(level):
    """bycle_arrange"""
    if level + 1 > level_length:
        # check constrain
        check_constrain()
        return

    for i in range(level, level_length):
        data_table[1][level], data_table[1][i] = data_table[1][i], data_table[1][level]

        bycle_arrange(level + 1)

        data_table[1][level], data_table[1][i] = data_table[1][i], data_table[1][level]


def name_arrange(level):
    """name_arrange"""
    if level + 1 > level_length:
        # can check also
        bycle_arrange(0)
        return

    for i in range(level, level_length):
        data_table[0][level], data_table[0][i] = data_table[0][i], data_table[0][level]

        name_arrange(level + 1)

        data_table[0][level], data_table[0][i] = data_table[0][i], data_table[0][level]


def all_arrange(
    data_table,
    dimension_length,
    level_length,
    dimension,
    level,
):
    if dimension >= dimension_length:
        # all dimension arranged
        check_constrain()
        return

    if level >= level_length:
        # level arranged
        # change dimension
        all_arrange(data_table, dimension_length, level_length, dimension + 1, 0)
        return

    for i in range(level, level_length):

        data_table[dimension][level], data_table[dimension][i] = (
            data_table[dimension][i],
            data_table[dimension][level],
        )

        # next level
        all_arrange(data_table, dimension_length, level_length, dimension, level + 1)

        data_table[dimension][level], data_table[dimension][i] = (
            data_table[dimension][i],
            data_table[dimension][level],
        )


if __name__ == "__main__":
    name_arrange(0)